package com.leetcode.partition14;

import java.util.HashMap;
import java.util.Map;

/**
 * @author rkc
 * @date 2022/9/2 9:05
 */
public class LC1371每个元音包含偶数次的最长子字符串 {

    private Map<Integer, Integer> map = new HashMap<>();

    public int findTheLongestSubstring(String s) {
        int state = 0, ans = 0;
        map.put(state, -1);
        for (int i = 0; i < s.length(); i++) {
            switch (s.charAt(i)) {
                case 'a': state ^= 1; break;
                case 'e': state ^= 1 << 1; break;
                case 'i': state ^= 1 << 2; break;
                case 'o': state ^= 1 << 3; break;
                case 'u': state ^= 1 << 4; break;
            }
            if (map.containsKey(state)) ans = Math.max(ans, i - map.get(state));
            else map.put(state, i);
        }
        return ans;
    }
}
